// 分组管理
import request from '@/utils/request';
import {object2Url} from "@/utils/trans";


//添加分组
export async function addGroup (data) {
  const res = await request.post('/business/matrix/group/add', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//修改分组(暂用于修改分组名称）
export async function updateGroup (data) {
  const res = await request.post('/business/matrix/group/update', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//删除分组【真实删除】
export async function delGroup (data) {
  const res = await request.post('/business/matrix/group/delete', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//查询分组【分页查询】
export async function queryGroup (data) {
  const res = await request.post('/business/matrix/group/page', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

// 获取IP属地
export async function areaList(areaName) {
  const ts = new Date().getTime();
  const ua = navigator.userAgent;
  console.log("areaName",areaName)
  const us = {
    ts,
    ua,
    areaName: areaName
  };
  // ${object2Url(us)} get 链接传值
  let url = `/business/matrix/area/list${object2Url(us)}`
  const res = await request.get(url, us);
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.message));
}

// 工作台——矩阵管理查询数据
export async function queryMatrix (data) {
  const res = await request.post('/business/matrix/dypublish/pageCount', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//查询发布管理——发布列表【分页查询】
export async function getPublishPage (data) {
  const res = await request.post('/business/matrix/dypublish/page', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

//查询发布管理——发布列表【分页查询】：快手单独查询
export async function getKSPage (data) {
  const res = await request.post('/business/matrixkspublish/page', data)
  if (res.data.code === 2000) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}




//删除发布管理——发布列表【分页查询】
export async function delDypublish (data) {
  const res = await request.post('/business/matrix/dypublish/delete', data)
  if (res.data.code === 2000) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


// 矩阵——发布管理（列表）—— 终止任务接口
export async function terminateTask (data) {
  const res = await request.post('/business/matrix/dypublish/terminateTask', data)
  if (res.data.code === 2000) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.msg))
}


// 矩阵列表——查询进度——数据刷新接口
export async function matrixDataRefresh (data) {
  const res = await request.post('/business/MerchantManagement/dataRefresh', data)
  if (res.data.code === 2000) {
    return res.data.data
  }
  return Promise.reject(new Error(res.data.msg))
}

